#include "mainmenu.h"
#include "ui_mainmenu.h"

MainMenu::MainMenu(QWidget *parent, QString file) :
    QMainWindow(parent),
    ui(new Ui::MainMenu)
{
    ui->setupUi(this);
    this->setFixedSize(800,600);

    filename = file;
    resX = 800;
    resY = 600;
    hard = cheat = false;

    this->ui->background->setGeometry(0,0,800,600);
    QPixmap *bkground = new QPixmap("Images\\OpeningScreen.png");
    this->ui->background->setPixmap(*bkground);
    this->ui->background->show();
}

MainMenu::~MainMenu()
{
    delete ui;
}

void MainMenu::on_newGameBtn_clicked()
{
    Game *g = new Game(this, filename);
    g->show();
    this->hide();
    g->StartTimers();
}

void MainMenu::on_loadBtn_clicked()
{
    Game *g = new Game(this, filename);

    QString filename = QFileDialog::getOpenFileName(this, "Load Form", "Saves", "");
    QFile file(filename);

    if (!file.open(QIODevice::ReadOnly)){
        QMessageBox::information(this, tr("Unable to load file"), file.errorString());
        return;
    }

    QDataStream in(&file);
    in.setVersion(QDataStream::Qt_4_6); // Change this based on current Qt version

    int l,x,y,ym,t,d;

    in >> l;  //level
    in >> x;  //location
    in >> y;
    in >> ym; //speed
    in >> t; //Time spent
    in >> d; //Deaths

    file.close();

    this->hide();
    g->LoadGame(l,x,y,ym,t,d);
    g->StartTimers();
}

void MainMenu::on_instructBtn_clicked()
{
    Instructions *i = new Instructions(this);
    i->show();
    this->hide();
}

void MainMenu::on_settBtn_clicked()
{
    Settings *s = new Settings(this);
    s->show();
    this->hide();
}
